package com.jinkaimen.goodcash.ui.activity;

import android.view.View;
import android.widget.BaseAdapter;

import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseRefreshListViewActivity;
import com.ht.baselibs.ui.widget.TitleBarView;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.SharedPreferencesUtils;
import com.ht.baselibs.utils.UIUtils;
import com.jinkaimen.goodcash.bean.SaleListBean;
import com.jinkaimen.goodcash.bean.SaleListItemBean;
import com.jinkaimen.goodcash.dao.AccountDao;
import com.jinkaimen.goodcash.manager.ApiManager;
import com.jinkaimen.goodcash.ui.adapter.SaleManagerAdapter;

import java.util.List;

import retrofit2.Call;
import retrofit2.Response;

public class SaleManagerActivity extends BaseRefreshListViewActivity<SaleListItemBean> {

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected boolean isInitLoadData() {
        return false;
    }

    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("店员管理").addActions(
                new TitleBarView.Action("新增店员") {
                    @Override
                    public void performAction(View view) {
                        ActivityUtils.startActivity(SaleManagerActivity.this, SaleDetailActivity.class);
                    }
                }
        );
    }

    @Override
    protected View getHeaderView() {
        return null;
    }

    @Override
    protected void initChildDataFromCache() {

    }

    @Override
    protected BaseAdapter getAdapter() {
        return new SaleManagerAdapter(this, mDataList);
    }

    @Override
    protected void load() {
        ApiManager.getApi().saleList(
                "HSY001022",
                AccountDao.getInstance().getAccount().id,
                SharedPreferencesUtils.getLong("master_shop_id", 0)
        ).enqueue(new NetCallBack<SaleListBean>() {
            @Override
            protected void onSuccess(Call<SaleListBean> call, Response<SaleListBean> response) {
                mDataList.clear();
                if (response.body().appAuUserList != null){
                    mDataList.addAll(response.body().appAuUserList);
                } else {
                    UIUtils.showToast("暂无店员");
                }
            }

            @Override
            protected void hiddenProgress() {
                onRefreshCompleteSuccess();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        load();
    }

    @Override
    protected boolean hasMoreData() {
        return false;
    }

    @Override
    protected void onLoadMore(List<SaleListItemBean> dataList) {

    }
}
